package com.xxxx.spring.test.jdkTest;

import java.lang.reflect.Method;

public class MyInvocationHandler implements InvocationHandler{

    private final Object target; // 被代理对象

    public MyInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        // 在方法调用前添加逻辑
        System.out.println("Before method: " + method.getName());

        // 调用目标对象的方法
        Object result = method.invoke(target, args);

        // 在方法调用后添加逻辑
        System.out.println("After method: " + method.getName());

        return result;
    }
}
